跳到主要内容

simpread-Centos7 安装部署 SonarQube7.9.1 教程

SonarQube部署

1、原文链接

LTS7.9

**二进制方式安装参考文档:**https://www.cnblogs.com/mascot1/p/11179767.html

image-20230624101936269

image-20230624101954104

2、本地路径

image-20230921062903346

具体步骤

本文由 简悦 SimpRead 转码, 原文地址 www.cnblogs.com

  1. 参考文档

LTS 7.9.1 新特性:https://www.sonarqube.org/sonarqube-7-9-lts/

JDK11 下载地址: 链接: https://pan.baidu.com/s/1VGEUd2nPzsDeOE2Ycrcmqg  密码: gpx9

  1. 下载软件包

下载链接: https://www.sonarqube.org/downloads/

  1. 添加系统用户

useradd sonarqube
passwd sonarqube

  1. 优化系统参数

sysctl -w  vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -u 4096 sonarqube
ulimit -n 65536 sonarqube

  1. 解压安装包

mv sonarqube-7.9.1.zip  /home/sonarqube/
chown -R sonarqube:sonarqube /home/sonarqube/
su - sonarqube
yum -y install unzip
unzip sonarqube-7.9.1.zip

  1. 更改配置文件

vim sonarqube-7.9.1/conf/sonar.properties
 
[sonarqube@localhost ~]$ grep -v "^#" sonarqube-7.9.1/conf/sonar.properties | grep -v "^$"
sonar.jdbc.username=sonarqube
sonar.jdbc.password=meiyoumima
sonar.jdbc.url=jdbc:postgresql://127.0.0.1/sonarqube

  1. 安装 PostgreSQL# 下载 pg9.6 源

_yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install postgresql96-server postgresql96-contrib
#初始化db
/usr/pgsql-9.6/bin/postgresql96-setup initdb
 
#启动服务、开机自启
systemctl start postgresql-9.6
systemctl enable postgresql-9.6
 
#防火墙
firewall-cmd --add-service=postgresql --permanent
firewall-cmd --reload
     
#登录数据库
su - postgres
psql -U postgres
ALTER USER postgres with encrypted password 'xxxxxx';
\q
exit
#创建sonarqube用户
create user sonarqube with password 'xxxxx';
create database sonarqube owner sonarqube;
grant all  on database sonarqube to sonarqube;
create schema my_schema;
 
#开启远程访问
vi /var/lib/pgsql/9.6/data/postgresql.conf   #listen_addresses = '*' 
vi /var/lib/pgsql/9.6/data/pg_hba.conf
systemctl restart postgresql-9.6.service
#pg_hba.conf_

# IPv4 local connections:
host    all             all             0.0.0.0/0            trust
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident
host    all     all       0.0.0.0/0                ident

  1. 添加系统服务

ln -s /home/sonarqube/sonarqube-7.9.1/bin/linux-x86-64/sonar.sh  /usr/bin/sonar
 
vim /etc/init.d/sonarqube
 
 
 
#!/bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
### END INIT INFO
 
/usr/bin/sonar $*
 
 
 
chkconfig --add sonarqube
chkconfig sonarqube on
 
service sonarqube status

FAQ

  1. JDK11 错误: 需要安装 JDK11
[sonarqube@localhost linux-x86-64]$ ./sonar.sh  console
Running SonarQube...
wrapper  | --> Wrapper Started as Console
wrapper  | Launching a JVM...
jvm 1    | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
jvm 1    |
jvm 1    | 20:46:06.753 [WrapperSimpleAppMain] WARN org.sonar.application.config.JdbcSettings - JDBC URL is recommended to have the property 'rewriteBatchedStatements=true'
jvm 1    | 20:46:06.764 [WrapperSimpleAppMain] WARN org.sonar.application.config.JdbcSettings - JDBC URL is recommended to have the property 'useConfigs=maxPerformance'
jvm 1    |
jvm 1    | WrapperSimpleApp: Encountered an error running main: java.lang.IllegalStateException: SonarQube requires Java 11+ to run
jvm 1    | java.lang.IllegalStateException: SonarQube requires Java 11+ to run
jvm 1    |      at org.sonar.application.App.checkJavaVersion(App.java:93)
jvm 1    |      at org.sonar.application.App.start(App.java:56)
jvm 1    |      at org.sonar.application.App.main(App.java:98)
jvm 1    |      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
jvm 1    |      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
jvm 1    |      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
jvm 1    |      at java.lang.reflect.Method.invoke(Method.java:498)
jvm 1    |      at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
jvm 1    |      at java.lang.Thread.run(Thread.java:748)
wrapper  | <-- Wrapper Stopped

2.MySQL 数据库不支持